"use strict";
cc._RF.push(module, '69c75Aa1fJO2YH7SHFZs1bR', 'level_PeopleArcheryUnitBase');
// scripts/levelBundles/level_PeopleArchery/base/level_PeopleArcheryUnitBase.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var gameEngine_1 = require("../../../engines/gameEngine");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var level_PeopleArcheryUnitBase = /** @class */ (function (_super) {
    __extends(level_PeopleArcheryUnitBase, _super);
    function level_PeopleArcheryUnitBase() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        /**血量 */
        _this._hp = 0;
        /**最大血量 */
        _this._maxHp = 0;
        /** 攻速*/
        _this._atkSpd = 0;
        /**攻速加成 */
        _this._atkSpdAdd = 0;
        /** 攻击力 */
        _this._atk = 0;
        /**移动速度 */
        _this._moveSpd = 0;
        /**最小攻击速度 */
        _this._minAtkSpd = 0.25;
        /**最大攻击速度 */
        _this._maxAtkSpd = 2;
        /**最小攻击力 */
        _this._minAtk = 0;
        /**每五秒回血量 */
        _this._revitalize = 0;
        /**射击伤害加成 */
        _this._atkAddition = 0;
        /**血量收益 */
        _this._hpBenefit = 1;
        /**撞击后恢复的血量 */
        _this._strikeRecover = 0;
        /**每局金币加成 */
        _this._goldAddition = 0;
        /**暴击几率 */
        _this._criticalPro = 0;
        /**暴击伤害加成 */
        _this._criticalAddition = 0.5;
        /**射击吸血率 */
        _this._shotLeech = 0;
        /**血量上限加成 */
        _this._maxHpAddition = 0;
        /**回血增强 */
        _this._revitalizeAddition = 0;
        /**减伤 */
        _this._reduceDamage = 0;
        /**boss血量降低 */
        _this._bossHpReduce = 0;
        /**每五秒回百分比血量 */
        _this._revitalizePercent = 0;
        /**击败boss时回复百分比血量 */
        _this._bossDeathRevitalizePercent = 0;
        /** 伤害加成2 */
        _this._atkAddition2 = 1;
        /**是否死亡 */
        _this.isDeath = false;
        _this.level = null;
        /** 两秒回复计时 */
        _this.revitAlizeTime = 0;
        /** 五秒回复计时 */
        _this.revitAlizePercentTime = 0;
        /**当前的所有法宝 */
        _this._weapons = [];
        return _this;
    }
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "hp", {
        /**获取当前血量 */
        get: function () { return this._hp; },
        /**设置当前血量 */
        set: function (hp) { this._hp = Math.floor(Math.min(hp, this.maxHp)); },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "maxHp", {
        /**获取最大生命值 */
        get: function () {
            //血量加成
            var addition = this._maxHp * this.maxHpAddition;
            return this._maxHp + addition;
        },
        /**设置最大生命值 */
        set: function (maxHp) { this._maxHp = Math.floor(maxHp); },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "realMaxHp", {
        /**获取真实的最大生命值 */
        get: function () {
            return this._maxHp;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "atkSpd", {
        /**获取攻速 */
        get: function () { return this._atkSpd; },
        /**设置攻速 */
        set: function (atkSpd) { this._atkSpd = atkSpd; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "atkSpdAdd", {
        /**获取攻速加成 */
        get: function () { return this._atkSpdAdd; },
        /**设置攻速加成 */
        set: function (atkSpdAdd) { this._atkSpdAdd = atkSpdAdd; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "shotAtk", {
        get: function () {
            var atk = this._atk;
            var atkAddition = this.atkAddition;
            var addition = Math.floor(atkAddition * atk);
            var addition2 = this.atkAddition2;
            var realAddition = (atk + addition) * addition2;
            return realAddition;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "atk", {
        /**获得攻击力 */
        get: function () {
            var atk = this._atk;
            return atk;
        },
        /**设置攻击力 */
        set: function (atk) { this._atk = Math.max(atk, this._minAtk); },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "moveSpd", {
        /**移动速度 */
        get: function () { return this._moveSpd; },
        /**设置移动速度 */
        set: function (moveSpd) { this._moveSpd = moveSpd; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "minAtk", {
        /**获取最小攻击力 */
        get: function () { return this._minAtk; },
        /**获取最大攻击力 */
        set: function (minAtk) { this._minAtk = minAtk; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "minAtkSpd", {
        /**获取最小攻速 */
        get: function () { return this._minAtkSpd; },
        /**设置最小攻速 */
        set: function (minAtkSpd) { this._minAtkSpd = minAtkSpd; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "maxAtkSpd", {
        /**获取最大攻速 */
        get: function () { return this._maxAtkSpd; },
        /**设置最大攻速 */
        set: function (maxAtkSpd) { this._maxAtkSpd = maxAtkSpd; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "revitAlize", {
        /**获取五秒回复 */
        get: function () { return this._revitalize; },
        /**设置五秒回复 */
        set: function (revitalize) { this._revitalize = Math.max(0, revitalize); },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "atkAddition", {
        /**攻击加成 */
        get: function () { return this._atkAddition; },
        /**设置攻击加成 */
        set: function (atkAddition) { this._atkAddition = Math.max(0, atkAddition); },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "atkAddition2", {
        /**攻击加成 */
        get: function () { return this._atkAddition2; },
        /**设置攻击加成 */
        set: function (atkAddition) { this._atkAddition2 = Math.max(0, atkAddition); },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "hpBenefit", {
        /**获取血量收益 */
        get: function () { return this._hpBenefit; },
        /**设置血量收益 */
        set: function (hpBenefit) { this._hpBenefit = Math.max(1, hpBenefit); },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "strikeRecover", {
        /**获取撞击回血 */
        get: function () { return this._strikeRecover; },
        /**设置撞击回血 */
        set: function (strikeRecover) { this._strikeRecover = Math.max(0, strikeRecover); },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "goldAddition", {
        /**获取金币加成 已完成 */
        get: function () { return this._goldAddition; },
        /**设置金币加成 */
        set: function (addition) { this._goldAddition = Math.max(0, addition); },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "criticalPro", {
        /** 获取暴击率 已完成 */
        get: function () { return this._criticalPro; },
        /** 设置暴击率*/
        set: function (criticalPro) { this._criticalPro = Math.max(0, criticalPro); },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "criticalAddition", {
        /**获取暴击伤害加成 已完成 */
        get: function () { return this._criticalAddition; },
        /**设置暴击伤害加成 */
        set: function (criticalAddition) { this._criticalAddition = Math.max(0, criticalAddition); },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "shotLeech", {
        /**获取射击吸血率 已完成 */
        get: function () { return this._shotLeech; },
        /**设置射击吸血率 */
        set: function (shotLeech) { this._shotLeech = Math.max(0, shotLeech); },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "maxHpAddition", {
        /** 获取血量上限加成 已完成 */
        get: function () { return this._maxHpAddition; },
        /** 设置血量上限加成 */
        set: function (maxHpAddition) { this._maxHpAddition = Math.max(0, maxHpAddition); },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "revitalizeAddition", {
        /**获取回血增强 已完成 */
        get: function () { return this._revitalizeAddition; },
        /**设置回血增强 */
        set: function (revitalizeAddition) { this._revitalizeAddition = Math.max(0, revitalizeAddition); },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "reduceDamage", {
        /**获取伤害减免 已完成 */
        get: function () { return this._reduceDamage; },
        /** 设置伤害减免 */
        set: function (reduceDamage) { this._reduceDamage = Math.max(0, reduceDamage); },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "bossHpReduce", {
        /**获取boss血量降低 已完成 */
        get: function () { return this._bossHpReduce; },
        /** 设置boss血量降低 */
        set: function (bossHpReduce) { this._bossHpReduce = Math.max(0, bossHpReduce); },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "revitalizePercent", {
        /**获取每五秒回百分比血量 已完成 */
        get: function () { return this._revitalizePercent; },
        /**设置每五秒回百分比血量 */
        set: function (revitalizePercent) { this._revitalizePercent = Math.max(0, revitalizePercent); },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(level_PeopleArcheryUnitBase.prototype, "bossDeathRevitalizePercent", {
        /**获取击败boss时回复百分比血量 */
        get: function () { return this._bossDeathRevitalizePercent; },
        /**设置击败boss时回复百分比血量 */
        set: function (bossDeathRevitalizePercent) { this._bossDeathRevitalizePercent = Math.max(0, bossDeathRevitalizePercent); },
        enumerable: false,
        configurable: true
    });
    /**绑定关卡 */
    level_PeopleArcheryUnitBase.prototype.bindLevel = function (level) {
        this.level = level;
    };
    /**
     * 单位受到伤害
     * @param atk 伤害
     * @param atkType 伤害类型 0是弓箭伤害 1是撞击伤害
    */
    level_PeopleArcheryUnitBase.prototype.unitBeHurt = function (atk, atkType, criticalFlag) {
        return __awaiter(this, void 0, void 0, function () {
            var hp, lastHp;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        //计算伤害减免后的伤害
                        atk -= Math.floor(atk * this.reduceDamage);
                        hp = this.hp;
                        atk = Math.floor(atk);
                        lastHp = hp - atk;
                        this.level.addSubLb(atk, this.node, criticalFlag);
                        this.hp = Math.max(0, lastHp);
                        gameEngine_1.default.getManagers().soundMgr.playSound("peopleArcherySound/hit");
                        gameEngine_1.default.getManagers().soundMgr.playVibrate();
                        if (!(lastHp <= 0)) return [3 /*break*/, 2];
                        // 死亡
                        return [4 /*yield*/, this.unitDeath()];
                    case 1:
                        // 死亡
                        _a.sent();
                        return [3 /*break*/, 4];
                    case 2:
                        this.unitBeHurtNotDieFun(atkType);
                        return [4 /*yield*/, this.unitBeHurtAni()];
                    case 3:
                        _a.sent();
                        _a.label = 4;
                    case 4: return [2 /*return*/];
                }
            });
        });
    };
    /**
     * 单位未受到致命伤害
     * @param atkType 伤害类型
    */
    level_PeopleArcheryUnitBase.prototype.unitBeHurtNotDieFun = function (atkType) {
        switch (atkType) {
            case "0": {
                break;
            }
            case "1": {
                if (this.strikeRecover > 0) {
                    var addHp = this.strikeRecover;
                    if (addHp > 0) {
                        // 撞击回血
                        this.level.parseDataAddPeople({ param_type: "0", option_param: addHp.toString(), reCoverMaxHp: "0" });
                    }
                }
                break;
            }
        }
    };
    /**
     * 单位受到致命伤
     * @param atk 伤害值
     * @param atkType 伤害类型
     */
    level_PeopleArcheryUnitBase.prototype.unitBeHurtDie = function (atk, atkType) {
        switch (atkType) {
            case "0": {
                break;
            }
            case "1": {
                break;
            }
        }
    };
    /**单位受到伤害动画 */
    level_PeopleArcheryUnitBase.prototype.unitBeHurtAni = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/];
            });
        });
    };
    /** 单位死亡 */
    level_PeopleArcheryUnitBase.prototype.unitDeath = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        this.isDeath = true;
                        this.node.getComponent(cc.Collider).enabled = false;
                        return [4 /*yield*/, this.unitDeathAni()];
                    case 1:
                        _a.sent();
                        this.unitDestroy();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**单位死亡动画 */
    level_PeopleArcheryUnitBase.prototype.unitDeathAni = function () {
        return __awaiter(this, void 0, void 0, function () {
            var _this = this;
            return __generator(this, function (_a) {
                return [2 /*return*/, new Promise(function (resolve) {
                        cc.tween(_this.node).to(0.2, { opacity: 0 }).call(resolve).start();
                    })];
            });
        });
    };
    /**销毁单位 */
    level_PeopleArcheryUnitBase.prototype.unitDestroy = function () {
        this.node.destroy();
        this.node.removeFromParent();
    };
    /**碰撞开始 */
    level_PeopleArcheryUnitBase.prototype.onCollisionEnter = function (other, self) {
    };
    /**持续碰撞 */
    level_PeopleArcheryUnitBase.prototype.onCollisionStay = function (other, self) {
    };
    /**碰撞结束 */
    level_PeopleArcheryUnitBase.prototype.onCollisionExit = function (other, self) {
    };
    level_PeopleArcheryUnitBase.prototype.update = function (dt) {
        var tIndex = this.level.unitContent.y - this.node.y;
        tIndex = Math.min(tIndex, cc.macro.MAX_ZINDEX);
        tIndex = Math.max(tIndex, cc.macro.MIN_ZINDEX);
        this.node.zIndex = tIndex;
        if (this.level.gamePauseFlag || this.isDeath) {
            return;
        }
        this.revitAlizeTime += dt;
        if (this.revitAlizeTime >= 2) {
            // 每2秒回血
            this.revitAlizeTime = 0;
            if (this.revitAlize > 0) {
                var revitAlize = this.revitAlize;
                var revitalizeAddition = this.revitalizeAddition;
                var addition = revitAlize * revitalizeAddition;
                var data = { param_type: "0", option_param: revitAlize + addition, reCoverMaxHp: "0" };
                this.level.parseDataAddPeople(data);
            }
        }
        this.revitAlizePercentTime += dt;
        if (this.revitAlizePercentTime >= 5) {
            // 每五秒回血
            this.revitAlizePercentTime = 0;
            if (this.revitalizePercent > 0) {
                var revitAlizeHp = this.revitalizePercent * this.maxHp;
                var data = { param_type: "0", option_param: revitAlizeHp, reCoverMaxHp: "0" };
                this.level.parseDataAddPeople(data);
            }
        }
    };
    level_PeopleArcheryUnitBase.prototype.autoDeath = function () {
        if (this.node.y < -1961) {
            this.unitDestroy();
        }
    };
    level_PeopleArcheryUnitBase.prototype.addOneWeapon = function (weaponId) {
        this._weapons.push(weaponId);
    };
    level_PeopleArcheryUnitBase = __decorate([
        ccclass
    ], level_PeopleArcheryUnitBase);
    return level_PeopleArcheryUnitBase;
}(cc.Component));
exports.default = level_PeopleArcheryUnitBase;

cc._RF.pop();